﻿using NUnit.Framework;
using Nuwanda.Common;
using Nuwanda.TfsSpotlight.Shell.Services.Interfaces;
using Nuwanda.TfsSpotlight.Views.Query;
using Rhino.Mocks;
using Nuwanda.TfsSpotlight.Commands;

namespace TfsSpotlight.Tests.Commands
{
    [TestFixture]
    [Author("Bartłomiej Legiędź")]
    public class GoToNextWorkItemCommandTests
    {
        private MockRepository _mocks;
        private ITabsService _tabsServiceMock;
        private IQueryPresenter _queryPresenterMock;

        private ICommand _goToNextWorkItemCommandUnderTest;

        [SetUp]
        public void SetUp()
        {
            this._mocks = new MockRepository();
            this._tabsServiceMock = this._mocks.DynamicMock<ITabsService>();
            this._queryPresenterMock = this._mocks.DynamicMock<IQueryPresenter>();

            this._goToNextWorkItemCommandUnderTest = new GoToNextWorkItemCommand(this._tabsServiceMock);
        }

        [Test]
        public void WhenAskedTo_RunCommand_And_ThereIsQueryTabSelected_Should_HandleMoveToNextWorkItem()
        {
            using (this._mocks.Record())
            {
                Expect.Call(this._tabsServiceMock.GetActiveTab<IQueryPresenter>()).Return(this._queryPresenterMock);
                this._queryPresenterMock.HandleSelectNextWorkItem();
            }

            using (this._mocks.Playback())
            {
                this._goToNextWorkItemCommandUnderTest.Execute();
            }
        }

        [Test]
        public void WhenAskedTo_RunCommand_And_ThereIsNotQueryTabSelected_Should_SkipExecution()
        {
            using (this._mocks.Record())
            {
                Expect.Call(this._tabsServiceMock.GetActiveTab<IQueryPresenter>()).Return(null);
                this._queryPresenterMock.HandleSelectNextWorkItem();
                LastCall.Repeat.Never();
            }

            using (this._mocks.Playback())
            {
                this._goToNextWorkItemCommandUnderTest.Execute();
            }
        }
    }
}